package com.secsys.service.impl;



import java.util.Date;
import java.util.List;

import com.secsys.model.TbSysFriends;
import com.secsys.model.TbSysUser;
import com.secsys.service.FriendsService;
import com.secsys.util.DateFormatUtils;

/**
 * @Description 好友业务逻辑接口实现类
 * @author LiusQ
 * 
 */
public class FriendsServiceImpl extends ServiceImpl<TbSysFriends, Integer>
		implements FriendsService {
	/**
	 * @Description 添加好友
	 */
	@Override
	public void addFriends(Integer userId, Integer friendsId) {
		// TODO Auto-generated method stub
		 TbSysUser user1=new TbSysUser();
		  user1.setId(userId);
		  TbSysUser user2=new TbSysUser();
		  user2.setId(friendsId);
		  TbSysFriends friends=new TbSysFriends();
		  Date addDate=new Date();
		  friends.setAddTime(DateFormatUtils.convertStringToDateTime(DateFormatUtils.convertDateTimeToString(addDate)));
		  friends.setTbSysUserByUserNo(user1);
		  friends.setTbSysUserByFriendsId(user2);
		  dao.save(friends);
		 
		 
	}
    
	/**
	 * @Description  通过ID查询好友列表
	 */
	@Override
	public List<TbSysFriends> queryFriendsById(Integer id) {
		// TODO Auto-generated method stub
		String hql="from TbSysFriends t where t.tbSysUserByUserNo.id=?";
	List<TbSysFriends> friendsList=	dao.find(hql, new Object[]{id});
		return friendsList!=null&&friendsList.size()>0?friendsList:null;
	}
    
	/**
	 * @Description 删除好友
	 */
	@Override
	public void delFriend(Integer id) {
		// TODO Auto-generated method stub
		TbSysFriends f=dao.load(id);  
		 
		dao.delete(f);
	}
    /**
     * @Description 查询好友
     */
	@Override
	public TbSysFriends queryFriendsByFriendId(int userId,int friendId) {
		// TODO Auto-generated method stub
		  String hql="from TbSysFriends t where t.tbSysUserByUserNo.id=? and t.tbSysUserByFriendsId.id=?";
		  List<TbSysFriends> friendsList=dao.find(hql, new Object[]{userId,friendId});
		return friendsList!=null&&friendsList.size()>0?friendsList.get(0):null;
	}

}
